package de.helen.ball;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

public class SensorAccel implements SensorEventListener{
	
	public static double X = 0;
	public static double Y = 0;
	public static double Z = 0;
	
	private boolean mInitialized; 
	private SensorManager mSensorManager; 
	private Sensor mAccelerometer; 
	private final float NOISE = (float) 2.0;
	
	private SensorAccel(){
		
	}
	
	public void OnCreate(SensorManager s){
		mInitialized = false;
		mSensorManager = s;
		mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
		mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
	}
	
	private static SensorAccel INSTANCE;
	
	public static SensorAccel GetInst(){
		if (INSTANCE != null) 
			return INSTANCE;
		else {
			INSTANCE = new SensorAccel();
			return INSTANCE;
		}
	}

	@Override
	public void onAccuracyChanged(Sensor arg0, int arg1) {
		
	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		X = event.values[0];
		Y = event.values[1];
		Z = event.values[2];
	}
	
	public void OnPause(){
		mSensorManager.unregisterListener(this);
	}
	
	public void OnResume(){
		mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
	}
}
